package com.myblockchain;

import com.alibaba.fastjson.JSON;
import com.myblockchain.utility.SpringUtil;
import com.myblockchain.p2p.P2PClient;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * @author Liu
 */
@SpringBootApplication(scanBasePackages = {"com.myblockchain"})
@RestController
public class Hello {


    @RequestMapping("/")
    public String Hi() throws Exception{
//        交易发起方
//        Wallet sender = Wallet.generateWallet();
//        接收方
//        Wallet receiver = Wallet.generateWallet();
//
//        TransactionInput transactionInput = TransactionInput.builder().build();
//        TransactionOutput transactionOutput = TransactionOutput.builder().build();
//        Transaction transaction = Transaction.builder().build();
//        transaction.sign(sender.getPrivateKey(),transaction);
        return JSON.toJSONString("9988776655443322");
    }



    public static void main(String[] args) {
        System.out.println("Hello world");
        SpringUtil.applicationContext  = SpringApplication.run(Hello.class, args);
        if (args.length>0){
            P2PClient p2PClient = new P2PClient();
            String url = "ws://localhost:"+args[0]+"/test";
            try {
                p2PClient.connectToPeer(url);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

    }

}
